package com.tigase.dao.JDBCDao;

import com.tigase.bean.TigaseUser;
import com.tigase.utils.BaseJDBCDao;

/**
 * Created by Mer on 2017/7/19.
 */

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.stereotype.Repository;



@Repository
public class UserJDBCDao extends BaseJDBCDao{
    @Resource
    private DataSource dataSource;

    /**
     * 根据用户名查找用户
     * @param userId 用户账号
     * @return
     */
    public String getUserByUserId(String userId){
        Connection connection = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try{
            connection = dataSource.getConnection();
            StringBuilder tempSql = new StringBuilder("select user_id  from t_user WHERE user_id= ? ");
            pstmt = connection.prepareStatement(tempSql.toString());
            pstmt.setString(1,userId);
            rs = pstmt.executeQuery();
            while(rs.next()){
               String sUserId= rs.getString("user_id");
                System.out.print(sUserId+"2784");
                return sUserId;
            }
        }catch(Exception e){
            e.printStackTrace();
//				log.error("获取数据（分钟）失败，具体原因:"+e.getMessage());
//				return new ArrayList<GrjbxxBean>();
        }finally {
            this.closeAllConnection(connection, pstmt, rs);
        }
        return null;
    }

}
